using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using service;
using Iservice;
using Demo.Net.Model;
using Utils;
namespace Demo.Net.BlogAPI.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class RRcontrollers : ControllerBase
    {
        private readonly IBaseService<RentRecord> _RentRecord;

        public RRcontrollers(IBaseService<RentRecord> RentRecord)
        {
            this._RentRecord = RentRecord;
        }
        // 查询所有反馈信息
        [HttpGet]
        public async Task<List<RentRecord>> FindAll()
        {
                return await _RentRecord.FindAll();
        }
        // 根据搜索条件查询反馈信息
         [HttpGet]
        public async Task<List<RentRecord>> FindAllByCondition(string searchTerm)
        {
                return await _RentRecord.FindAllByCondition(
                    s => s.Id.ToString() == searchTerm
                    || s.Owner.Name.Contains(searchTerm)
                    || s.ParkingSpace.Code.Contains(searchTerm)
                    || s.RentStartTime.ToString().Contains(searchTerm)
                    || s.RentEndTime.ToString().Contains(searchTerm)
                    );
        }
        //根据id查找
        [HttpGet]
        public async Task<List<RentRecord>> Find(int id)
        {
            return await _RentRecord.Find(s => s.Id == id);
        }
        //添加
        [HttpPost]
        public async Task<bool> Add(RentRecord RentRecords)
        {
            return await _RentRecord.Add(RentRecords);
        }
        //编辑
        [HttpPut]
        public async Task<bool> Update(RentRecord RentRecords)
        {

            return await _RentRecord.UpdateAsync(RentRecords);
        }
        [HttpDelete("{id}")]
        public async Task<ActionResult<ApiReturn>> Delect(int id)
        {
            var result = await _RentRecord.Delete(id);
            if (result)
            {
                return ApiRetrunsHelper.Success(result);
            }
            else
            {
                return ApiRetrunsHelper.Failed("没有数据");
            }

        }

    }
}